package com.jic.market.impl.overlay;

import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.market.entity.overlay.OverlayPromotionRule;
import com.jic.market.mapper.overlay.OverlayPromotionRuleMapper;
import com.jic.market.service.overlay.OverlayPromotionRuleService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 叠加规则活动规则表
 *
 * @author : seven
 * @version : v1.0.0
 * @email : 774329481@qq.com
 * @since : 2020-03-20 04:58:38
 */
@Service
public class OverlayPromotionRuleServiceImpl implements OverlayPromotionRuleService {

    @Autowired
    private OverlayPromotionRuleMapper overlayPromotionRuleMapper;

    @Override
    public long insert(OverlayPromotionRule overlayPromotionRule) {
        long flag = overlayPromotionRuleMapper.insert(overlayPromotionRule);
        return flag;
    }

    @Override
    public long delete(Long id) {
        return overlayPromotionRuleMapper.delete(id);
    }

    @Override
    public long update(OverlayPromotionRule overlayPromotionRule) {
        return overlayPromotionRuleMapper.update(overlayPromotionRule);
    }

    @Override
    public OverlayPromotionRule queryByPrimaryKey(Long id) {
        return overlayPromotionRuleMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<OverlayPromotionRule> query(OverlayPromotionRule overlayPromotionRule) {
        return overlayPromotionRuleMapper.query(overlayPromotionRule);
    }

    @Override
    public PageResult<OverlayPromotionRule> queryPage(OverlayPromotionRule overlayPromotionRule, Page pageQuery) {
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<OverlayPromotionRule> list = overlayPromotionRuleMapper.queryPage(startIndex, pageQuery.getLimit(), overlayPromotionRule);
        long count = overlayPromotionRuleMapper.queryPageCount(overlayPromotionRule);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }
}